<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
	</head>
	<body>
		<div id="app">
			<input type="text" v-model="inpValue">
			<button @click="add">添加</button>
			<ul>
				<li v-for="item in arr" :key="item.id">
				    <input type="checkbox"/>
				   {{item.name}}
				</li>
			</ul>
		</div>
		<script>
			new Vue({
				el:"#app",
				data:{
					inpValue:"",
					arr:[
						{id:0,name:"小韩"},
						{id:1,name:"小李"},
						{id:2,name:"小张"}
					]
				},
				methods:{
					add(){
						let obj={
							id:this.arr.length,
							name:this.inpValue
						}
						console.log(obj);
						//push():添加到数组的尾部      pop:删除数组的尾部
						//unshift():添加到数组的头部   shift:删除数组的顶部
						this.arr.unshift(obj);
						this.inpValue="";//添加完成，清空input
					}
				}
			})
		</script>
	</body>
</html>
